﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GBlog.Core.Data;
using System.Linq.Expressions;

namespace GBlog.Core.Service.Default
{
    public class ContentService<T> : IContentService<T> where T : class
    {
        private IRepository<T> Repository;

        public ContentService(IRepository<T> Repository)
        {
            this.Repository = Repository;
        }

        public IQueryable<T> GetAll()
        {
            return Repository.GetAll();
        }

        public T GetByID(int ID)
        {
            if (ID == 0)
            {
                return null;
            }
            return Repository.GetByID(ID);
        }

        public void Insert(T content)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            Repository.Insert(content);
        }

        public void Update(T content)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            Repository.Update(content);
        }

        public void Delete(T content)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            Repository.Delete(content);
        }

        public int Count()
        {
            return Repository.Count();
        }

        public int Count(Expression<Func<T, bool>> Predicate)
        {
            return Repository.Count(Predicate);
        }
    }
}